package com.xiaoyu.merchant.network;


import com.xiaoyu.commonlib.network.BaseNetworkManager;
import com.xiaoyu.commonlib.network.CommonHttpResponser;

import org.json.JSONArray;

import java.util.HashMap;

/**
 * Created by jk on 2018/9/27.
 */
public class NetworkManager {

    /**
     * 注册接口
     *
     * @param storeactel 手机号
     * @param verify     验证码
     * @param pas        密码
     * @param listener
     */
    public static void registerUser(String storeactel, String verify, String pas, CommonHttpResponser listener) {
        HashMap<String, String> params = new HashMap<>();
        params.put("storeactel", storeactel);
        params.put("verify", verify);
        params.put("pas", pas);
        BaseNetworkManager.getInstance().sendRequest(BaseNetworkManager.HTTP_REQUEST_TYPE.POST,
                NetworkConstants.REGISTER_URL, params, listener);
    }


    /**
     * 发送验证码接口
     *
     * @param usertel  手机号码
     * @param listener
     */
    public static void sendVerify(String usertel, CommonHttpResponser listener) {
        HashMap<String, String> params = new HashMap<>();
        params.put("storeactel", usertel);
        BaseNetworkManager.getInstance().sendRequest(BaseNetworkManager.HTTP_REQUEST_TYPE.POST,
                NetworkConstants.SEND_VERIFY_URL, params, listener);
    }

    /**
     * 重新设置密码
     *
     * @param storeactel 手机号
     * @param verify     验证码
     * @param pas        密码
     * @param listener
     */
    public static void modificationPwd(String storeactel, String verify, String pas, CommonHttpResponser listener) {
        HashMap<String, String> params = new HashMap<>();
        params.put("storeactel", storeactel);
        params.put("verify", verify);
        params.put("pas", pas);
        BaseNetworkManager.getInstance().sendRequest(BaseNetworkManager.HTTP_REQUEST_TYPE.POST,
                NetworkConstants.MODIFICATION_PWD_URL, params, listener);
    }


    /**
     * 登录接口
     *
     * @param storeactel 手机号
     * @param pas        密码
     * @param listener
     */
    public static void login(String storeactel, String pas, CommonHttpResponser listener) {
        HashMap<String, String> params = new HashMap<>();
        params.put("storeactel", storeactel);
        params.put("pas", pas);
        BaseNetworkManager.getInstance().sendRequest(BaseNetworkManager.HTTP_REQUEST_TYPE.POST,
                NetworkConstants.LOGIN_URL, params, listener);
    }
//---------------------------------------------申请开店-------------------------------------------------------

    /**
     * 申请开店
     *
     * @param token
     * @param storename      店铺名称
     * @param storeintroduce 店铺介绍
     * @param idcardfront    正面
     * @param idcardback     反面
     * @param imagefront     手持照
     * @param imageback      自拍照
     * @param storeaddresss  地址
     * @param listener
     */
    public static void applyOpenShop(String token, String storename, String storeintroduce, String idcardfront,
                                     String idcardback, String imagefront, String imageback, String storeaddresss, CommonHttpResponser listener) {
        HashMap<String, String> params = new HashMap<>();
        params.put("token", token);
        params.put("storename", storename);
        params.put("storeintroduce", storeintroduce);
        params.put("idcardfront", idcardfront);
        params.put("idcardback", idcardback);
        params.put("imagefront", imagefront);
        params.put("imageback", imageback);
        params.put("storeaddresss", storeaddresss);
        BaseNetworkManager.getInstance().sendRequest(BaseNetworkManager.HTTP_REQUEST_TYPE.POST,
                NetworkConstants.APPLY_SHOP, params, listener);
    }

    /**
     * 支付订单
     *
     * @param token
     * @param paytype  支付方式（支付宝ali  微信wx）
     * @param listener
     */
    public static void commitApply(String token, String paytype, CommonHttpResponser listener) {
        HashMap<String, String> params = new HashMap<>();
        params.put("token", token);
        params.put("paytype", paytype);
        BaseNetworkManager.getInstance().sendRequest(BaseNetworkManager.HTTP_REQUEST_TYPE.POST,
                NetworkConstants.COMMIT_APPLY, params, listener);

    }

    /**
     * 申请开店之后获取信息
     * @param token
     * @param listener
     */
    public static void openShopInfo(String token, CommonHttpResponser listener) {
        HashMap<String, String> params = new HashMap<>();
        params.put("token", token);
        BaseNetworkManager.getInstance().sendRequest(BaseNetworkManager.HTTP_REQUEST_TYPE.POST,
                NetworkConstants.OPEN_SHOP_INFO, params, listener);
    }


//-----------------------------------------------商品管理-----------------------------------------------------

    /**
     * 商品列表（上架与下架）
     *
     * @param token
     * @param goodsstate（1、上架 2、下架）
     * @param page
     * @param listener
     */
    public static void putawaySold(String token, String goodsstate, int page, CommonHttpResponser listener) {
        HashMap<String, String> params = new HashMap<>();
        params.put("token", token);
        params.put("goodsstate", goodsstate);
        params.put("page", page + "");
        BaseNetworkManager.getInstance().sendRequest(BaseNetworkManager.HTTP_REQUEST_TYPE.POST,
                NetworkConstants.COMMODITY_MANAGEMENT, params, listener);

    }


    /**
     * 商品列表 == >  根据商品类别
     *
     * @param token
     * @param goodstagid 商品类别id
     * @param page
     * @param listener
     */
    public static void getGoodsListByTag(String token, String goodstagid, int page, CommonHttpResponser listener) {
        HashMap<String, String> params = new HashMap<>();
        params.put("token", token);
        params.put("goodsstate", "1");//1、上架  2、下架
        params.put("goodstagid", goodstagid);
        params.put("page", page + "");
        BaseNetworkManager.getInstance().sendRequest(BaseNetworkManager.HTTP_REQUEST_TYPE.POST,
                NetworkConstants.COMMODITY_MANAGEMENT, params, listener);

    }

    /**
     * 上下架
     *
     * @param token
     * @param goodsid    商品id
     * @param goodsstate 1==上架  2==下架
     * @param listener
     */
    public static void upDownFrame(String token, String goodsid, String goodsstate, CommonHttpResponser listener) {
        HashMap<String, String> params = new HashMap<>();
        params.put("token", token);
        params.put("goodsid", goodsid);
        params.put("goodsstate", goodsstate);
        BaseNetworkManager.getInstance().sendRequest(BaseNetworkManager.HTTP_REQUEST_TYPE.POST,
                NetworkConstants.PUTAWAY_SOLDOUT, params, listener);

    }

    /**
     * 商品删除
     *
     * @param token
     * @param goodsid  商品id
     * @param listener
     */
    public static void deleteGoods(String token, String goodsid, CommonHttpResponser listener) {
        HashMap<String, String> params = new HashMap<>();
        params.put("token", token);
        params.put("goodsid", goodsid);
        BaseNetworkManager.getInstance().sendRequest(BaseNetworkManager.HTTP_REQUEST_TYPE.POST,
                NetworkConstants.GOODS_DELETE, params, listener);
    }

    /**
     * 商品详情
     * @param token
     * @param goodsid  商品id
     * @param listener
     */
    public static void goodsDetails(String token,String goodsid,CommonHttpResponser listener){
        HashMap<String,String> params = new HashMap<>();
        params.put("token",token);
        params.put("goodsid",goodsid);
        BaseNetworkManager.getInstance().sendRequest(BaseNetworkManager.HTTP_REQUEST_TYPE.POST,
                NetworkConstants.GOODS_DETAILS,params,listener);

    }

//--------------------------------------------上传商品----------------------------------------------------------

    /**
     * 添加商品
     *
     * @param token
     * @param goodsname        商品名
     * @param goodsxqimg       商品详情图用逗号拼接路径
     * @param goodslbimg       商品最上面的轮播图用逗号拼接路径
     * @param goodstagid       商品类别id
     * @param goodsfreight     商品运费
     * @param goodsimg         商品展示图
     * @param goodscontent     商品的文字描述
     * @param detail           商品规格
     * @param goodsdetailsname 商品规格名
     * @param goodsprice1      商品现价（真实的价格）
     * @param goodsinventory   改规格对应的库存
     * @param goodsdeimg       改规格对应的图片
     * @param listener
     */
    public static void uploadShop(String token, String goodsname, String goodsxqimg, String goodslbimg, String goodstagid, String goodsfreight,
                                  String goodsimg, String goodscontent, String detail, String goodsdetailsname, String goodsprice1, String goodsinventory,
                                  String goodsdeimg, CommonHttpResponser listener) {
        HashMap<String, String> params = new HashMap<>();
        params.put("token", token);
        params.put("goodsname", goodsname);
        params.put("goodsxqimg", goodsxqimg);
        params.put("goodslbimg", goodslbimg);
        params.put("goodstagid", goodstagid);
        params.put("goodsfreight", goodsfreight);
        params.put("goodsimg", goodsimg);
        params.put("goodscontent", goodscontent);
        params.put("detail", detail);
        params.put("goodsdetailsname", goodsdetailsname);
        params.put("goodsprice1", goodsprice1);
        params.put("goodsinventory", goodsinventory);
        params.put("goodsdeimg", goodsdeimg);
        BaseNetworkManager.getInstance().sendRequest(BaseNetworkManager.HTTP_REQUEST_TYPE.POST,
                NetworkConstants.UPLOAD_SHOP, params, listener);
    }

    /**
     * 商品类别
     *
     * @param listener
     */
    public static void shopCateGory(CommonHttpResponser listener) {
        BaseNetworkManager.getInstance().sendRequest(BaseNetworkManager.HTTP_REQUEST_TYPE.POST,
                NetworkConstants.SHOP_CATEGORY, null, listener);
    }


    //------------------------------------------------我的订单------------------------------------------------------

    /**
     * 我的订单
     *
     * @param token
     * @param orderstate 订单状态
     * @param page
     * @param listener
     */
    public static void orderList(String token, String orderstate, int page, CommonHttpResponser listener) {
        HashMap<String, String> params = new HashMap<>();
        params.put("token", token);
        params.put("orderstate", orderstate);
        params.put("page", page + "");
        BaseNetworkManager.getInstance().sendRequest(BaseNetworkManager.HTTP_REQUEST_TYPE.POST,
                NetworkConstants.ORDER_LIST, params, listener);

    }

    /**
     * 订单详情
     *
     * @param orderid  订单id
     * @param listener
     */
    public static void orderDetails(String orderid, CommonHttpResponser listener) {
        HashMap<String, String> params = new HashMap<>();
        params.put("orderid", orderid);
        BaseNetworkManager.getInstance().sendRequest(BaseNetworkManager.HTTP_REQUEST_TYPE.POST,
                NetworkConstants.ORDER_DETAILS, params, listener);
    }

    /**
     * 确认发货
     *
     * @param token
     * @param orderid         订单id
     * @param logisticsnumber 订单编号
     * @param logisticstype   物流公司名称
     * @param listener
     */
    public static void confirmShipments(String token, String orderid, String logisticsnumber, String logisticstype, CommonHttpResponser listener) {
        HashMap<String, String> params = new HashMap<>();
        params.put("token", token);
        params.put("orderid", orderid);
        params.put("logisticsnumber", logisticsnumber);
        params.put("logisticstype", logisticstype);
        BaseNetworkManager.getInstance().sendRequest(BaseNetworkManager.HTTP_REQUEST_TYPE.POST,
                NetworkConstants.CONFIRM_SHIPMENTS, params, listener);
    }

    /**
     * 售后
     *
     * @param orderid  要申请的点单编号
     * @param token
     * @param listener
     */
    public static void afterSale(String orderid, String token, CommonHttpResponser listener) {
        HashMap<String, String> params = new HashMap<>();
        params.put("orderid", orderid);
        params.put("token", token);
        BaseNetworkManager.getInstance().sendRequest(BaseNetworkManager.HTTP_REQUEST_TYPE.POST,
                NetworkConstants.AFTER_SALE, params, listener);
    }

    /**
     * @param token
     * @param refundid 申请退款的id
     * @param confirm  是否同意退款是y，否n
     * @param message  不同意退款时传的驳回原因
     * @param listener
     */
    public static void rejectAgree(String token, String refundid, String confirm, String message, CommonHttpResponser listener) {
        HashMap<String, String> params = new HashMap<>();
        params.put("token", token);
        params.put("refundid", refundid);
        params.put("confirm", confirm);
        params.put("message", message);
        BaseNetworkManager.getInstance().sendRequest(BaseNetworkManager.HTTP_REQUEST_TYPE.POST,
                NetworkConstants.REJECT_AGREE, params, listener);
    }

    //-------------------------------------------店铺管理---------------------------------------------------

    /**
     * 获取商品评价列表
     *
     * @param token
     * @param goodsid
     * @param page
     * @param listener
     */
    public static void getGoodsCommentList(String token, String goodsid, int page, CommonHttpResponser listener) {
        HashMap<String, String> params = new HashMap<>();
        params.put("token", token);
        params.put("goodsid", goodsid);
        params.put("page", page + "");
        BaseNetworkManager.getInstance().sendRequest(BaseNetworkManager.HTTP_REQUEST_TYPE.POST,
                NetworkConstants.GOODS_COMMENTS_URL, params, listener);
    }

    /**
     * 获取店铺评论列表
     *
     * @param token
     * @param page
     * @param listener
     */
    public static void getStoreCommentList(String token, int page, CommonHttpResponser listener) {
        HashMap<String, String> params = new HashMap<>();
        params.put("token", token);
        params.put("page", page + "");
        BaseNetworkManager.getInstance().sendRequest(BaseNetworkManager.HTTP_REQUEST_TYPE.POST,
                NetworkConstants.GOODS_COMMENTS_URL, params, listener);
    }

    /**
     * 获取商家信息
     *
     * @param token
     * @param listener
     */
    public static void getStoreInfo(String token, CommonHttpResponser listener) {
        HashMap<String, String> params = new HashMap<>();
        params.put("token", token);
        BaseNetworkManager.getInstance().sendRequest(BaseNetworkManager.HTTP_REQUEST_TYPE.POST,
                NetworkConstants.STORE_INFO_URL, params, listener);
    }

    /**
     * 我的钱包 信息
     *
     * @param token
     */
    public static void getMyWalletInfo(String token, CommonHttpResponser listener) {
        HashMap<String, String> params = new HashMap<>();
        params.put("token", token);
        BaseNetworkManager.getInstance().sendRequest(BaseNetworkManager.HTTP_REQUEST_TYPE.GET,
                NetworkConstants.MY_WALLET_INFO, params, listener);
    }

    /**
     * 我的钱包 - 明细列表
     *
     * @param token
     * @param page
     * @param listener
     */
    public static void walletList(String token, int page, CommonHttpResponser listener) {
        HashMap<String, String> params = new HashMap<>();
        params.put("token", token);
        params.put("page", page + "");
        BaseNetworkManager.getInstance().sendRequest(BaseNetworkManager.HTTP_REQUEST_TYPE.GET,
                NetworkConstants.WALLET_LIST, params, listener);
    }

    /**
     * 我的钱包 - 明细详情
     *
     * @param token
     * @param balanceid 明细id
     * @param listener
     */
    public static void walletDetails(String token, String balanceid, CommonHttpResponser listener) {
        HashMap<String, String> params = new HashMap<>();
        params.put("token", token);
        params.put("balanceid", balanceid);
        BaseNetworkManager.getInstance().sendRequest(BaseNetworkManager.HTTP_REQUEST_TYPE.POST,
                NetworkConstants.WALLET_DETAIL, params, listener);
    }

    /**
     * 银行卡提交
     *
     * @param token
     * @param cardnumber      卡号
     * @param bankname        开户行名称
     * @param cardname        开户姓名
     * @param extractpassword 提现密码
     * @param listener
     */
    public static void submitBindCard(String token, String cardnumber, String bankname, String cardname, String extractpassword, CommonHttpResponser listener) {
        HashMap<String, String> params = new HashMap<>();
        params.put("token", token);
        params.put("cardnumber", cardnumber);
        params.put("bankname", bankname);
        params.put("cardname", cardname);
        params.put("extractpassword", extractpassword);
        BaseNetworkManager.getInstance().sendRequest(BaseNetworkManager.HTTP_REQUEST_TYPE.POST,
                NetworkConstants.BIND_CARD, params, listener);

    }

    /**
     * 提现
     *
     * @param token
     * @param amount          提现金额
     * @param extractpassword 提现密码
     * @param listener
     */
    public static void withDrawal(String token, String amount, String extractpassword, CommonHttpResponser listener) {
        HashMap<String, String> params = new HashMap<>();
        params.put("token", token);
        params.put("amount", amount);
        params.put("extractpassword", extractpassword);
        BaseNetworkManager.getInstance().sendRequest(BaseNetworkManager.HTTP_REQUEST_TYPE.POST,
                NetworkConstants.WITH_DRAWAL, params, listener);
    }

    /**
     * 商家信息
     *
     * @param token
     * @param listener
     */
    public static void storeInfo(String token, CommonHttpResponser listener) {
        HashMap<String, String> params = new HashMap<>();
        params.put("token", token);
        BaseNetworkManager.getInstance().sendRequest(BaseNetworkManager.HTTP_REQUEST_TYPE.POST,
                NetworkConstants.STORE_INFO, params, listener);
    }

    /**
     * 修改商家信息
     *
     * @param token
     * @param storename
     * @param storeaddresss
     * @param storeimg
     * @param storeintroduce
     * @param listener
     */
    public static void modifStoreInfo(String token, String storename, String storeaddresss, String storeimg, String storeintroduce, CommonHttpResponser listener) {
        HashMap<String, String> params = new HashMap<>();
        params.put("token", token);
        params.put("storename", storename);
        params.put("storeaddresss", storeaddresss);
        params.put("storeimg", storeimg);
        params.put("storeintroduce", storeintroduce);
        BaseNetworkManager.getInstance().sendRequest(BaseNetworkManager.HTTP_REQUEST_TYPE.POST,
                NetworkConstants.MODIF_STORE_INFO, params, listener);
    }

    /**
     * 我的 -- 意见反馈
     *
     * @param yijian   反馈意见
     * @param listener
     */
    public static void feedBack(String yijian, CommonHttpResponser listener) {
        HashMap<String, String> param = new HashMap<>();
        param.put("yijian", yijian);
        BaseNetworkManager.getInstance().sendRequest(BaseNetworkManager.HTTP_REQUEST_TYPE.POST,
                NetworkConstants.FEED_BACK, param, listener);
    }

    /**
     * 修改支付密码
     *
     * @param token
     * @param yuan              原密码
     * @param extractpassword   新密码
     * @param reextractpassword 确认新密码
     * @param listener
     */
    public static void modificationPayPwd(String token, String yuan, String extractpassword, String reextractpassword, CommonHttpResponser listener) {
        HashMap<String, String> params = new HashMap<>();
        params.put("token", token);
        params.put("yuan", yuan);
        params.put("extractpassword", extractpassword);
        params.put("reextractpassword", reextractpassword);
        BaseNetworkManager.getInstance().sendRequest(BaseNetworkManager.HTTP_REQUEST_TYPE.POST,
                NetworkConstants.MODIFICATION_PAY_PWD, params, listener);
    }
}